//考试相关，公共操作提取到此文件
import examService from '@/services/exam/exam';
const service = new examService();
var examCommon = {
	methods:{
		//收藏试题
		collectSubject(){
		    let collection = this.curSubject.collection;
		    let param ={
		        subjectId:this.curSubject.subjectId,
		        type:collection,//0收藏，1取消收藏
		        collectType:1//1，试题；2，学习
		    };
		    service.collectSubject(param).then(response=>{
		        let msg = "操作失败"
		        if (response.success) {
		            this.curSubject.collection = collection == 0 ? 1 :0
					this.reDrawCollect(this);
		            msg = "操作成功"
		        }
				this.tip(msg)
		    })
		},
		//收藏重绘
		reDrawCollect(context){
		    // #ifdef APP-PLUS
		    let collectObj = {img:'examBar02',label:'未收藏'}
		    if(context.curSubject.collection == 1){
		        collectObj = {img:'examBar07',label:'已收藏'}
			}
		    const  richtext = `<img src="/static/exam/${collectObj.img}.png" width="20px" height="20px"/>` +
		        `<br/><font style="font-size:8px;">${collectObj.label}</font>`;
		    console.log('reDrawCollect:')
		    context.examStaticBar.drawRichText(richtext, {
		            top: '9px',
		            left: '0px',
		            width: '32px',
		            height: '100%'
		        }, {
		            onClick: function(e) {
		                context.collectSubject()
		            }
		        },
		        'collect'
		    );
		    // #endif
		},
	}
}
export default examCommon
